package com.bbx.taxi.client.Activity.Menu;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bbx.api.sdk.model.passanger.Return.Balance;
import com.bbx.api.sdk.model.passanger.Return.CouponCount;
import com.bbx.taxi.client.Activity.Base.BaseBBXActivity;
import com.bbx.taxi.client.Activity.Wallet.CouponActivity;
import com.bbx.taxi.client.Activity.Wallet.RechargeActivity;
import com.bbx.taxi.client.Bean.Wallect;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Util.IsDataFail;
import com.bbx.taxi.client.Util.RequestUtils;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 作者：严旭文 on 2016/12/26 15:11
 * 邮箱：420255048@qq.com
 * 我的钱包
 */
public class WalletActivity  extends BaseBBXActivity {
    @Bind(R.id.tv_account_balance)
    TextView tv_account_balance;
    @Bind(R.id.tv_coupon_count)
    TextView tv_coupon_count;
    @Bind(R.id.layout_account_balance)
    RelativeLayout layout_account_balance;
    @Bind(R.id.layout_coupon)
    RelativeLayout layout_coupon;
    @Bind(R.id.iv_coupon_new)
    ImageView iv_coupon_new;
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_wallet);
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onResume() {
        RequestUtils.requestCouponCount(this);
        RequestUtils.requesBalance(this);
        int count=0;
        try{count=Integer.parseInt(Wallect.couponCount);}catch (Exception e){}
        if(count>0&&!Wallect.isClickShareCoupon){
            iv_coupon_new.setVisibility(View.VISIBLE);
        }else{
            iv_coupon_new.setVisibility(View.GONE);
        }
        super.onResume();
    }

    @Override
    protected void initView() {
        setTitle(getString(R.string.my_coupon));
    }

    @Override
    protected void initData() {
        if(Wallect.couponCount==null){
            Wallect.couponCount="0";
        }
        if(Wallect.accountBalance==null){
            Wallect.accountBalance="0";
        }
        tv_coupon_count.setText(String.format(getString(R.string.coupon_count),Wallect.couponCount));
        tv_account_balance.setText(String.format(getString(R.string.account_balance),Wallect.accountBalance));
    }

    @Override
    @OnClick({ R.id.layout_account_balance, R.id.layout_coupon})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_account_balance:
                startActivity(new Intent(this, RechargeActivity.class));
                break;
            case R.id.layout_coupon:
                startActivity(new Intent(this, CouponActivity.class));
                break;
            default: super.onClick(v);break;
        }

    }

    @Override
    public void onNotifyData(DATA_STATUS data_status, DATA_TYPE data_type, int status, Object object) {
        switch (data_type) {
            case COUPONCOUNT:
                if (IsDataFail.isDataFail(data_status)) {
                    return;
                }
                try {
                CouponCount mCouponCount = (CouponCount) object;
                    Wallect.couponCount =mCouponCount.getCount()+"";
                } catch (Exception e) {
                }
                initData();
                break;
            case BALANCE:
                initData();
                break;
        }
        super.onNotifyData(data_status, data_type, status, object);
    }
}
